package com.example.serviceA.controller;

import com.example.serviceA.api.ServiceAAccountApi;
import com.example.serviceA.req.TransferOutReq;
import com.example.serviceA.service.IAccountService;
import org.bytesoft.compensable.Compensable;
import org.bytesoft.compensable.CompensableCancel;
import org.bytesoft.compensable.CompensableConfirm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Compensable(interfaceClass = ServiceAAccountApi.class, simplified = true)
@RestController
@RequestMapping("/account")
public class ServiceAAccountController implements ServiceAAccountApi {

    @Autowired
    private IAccountService accountService;

    @Override
    @Transactional
    @PostMapping("/transfer-out")
    public void transferOut(@RequestBody TransferOutReq req) {
        accountService.transferOut(req);
    }

    @CompensableConfirm
    @Transactional
    public void confirmTransferOut(@RequestBody TransferOutReq req) {
        accountService.confirmTransferOut(req);
    }

    @CompensableCancel
    @Transactional
    public void cancelTransferOut(@RequestBody TransferOutReq req) {
        accountService.cancelTransferOut(req);
    }

}
